package com.example.prayertracker;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.TextView;

public class Aisha extends Activity implements SensorEventListener {
	
	TextView proxText;
	TextView counts;
	SensorManager sm;
	Sensor proxSensor;
	int count = 0;
	TextView rakat;
	Intent intent = getIntent();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_aisha);
		//Adnan: force screen on -
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
		sm = (SensorManager) getSystemService(SENSOR_SERVICE);
		proxSensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
		proxText = (TextView) findViewById(R.id.textView1);
		counts = (TextView) findViewById(R.id.textView3);
		rakat = (TextView) findViewById(R.id.rakat);
		sm.registerListener(this, proxSensor, SensorManager.SENSOR_DELAY_NORMAL);

	}

	@Override										//Amir: Creates the menu item and grabs it from the activity_aisha
	public boolean onCreateOptionsMenu(Menu menu) {//XML in the menu subfolder
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.activity_aisha, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {//Amir: Tells the button what to do when it is clicked. In this case it
		switch (item.getItemId()) {						//The Prayselect, which is the mainactivity
		case R.id.home:
			startActivity(new Intent(this, PraySelect.class));
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}

	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {

	}

	@Override
	public void onSensorChanged(SensorEvent event) {
		proxText.setText(String.valueOf(event.values[0]));
		if (event.values[0] == 0.0) {
			count++;
			if (count <= 1) { // Amir: If they are on the first Sujood it will
				// display first rakat
				counts.setText("1st Rakat");
			}
			if (count == 2 || count == 3) { // Amir : If they DONE with the
				// second or on the third sujood it
				// will display 2nd Rakaat
				counts.setText("2nd Rakat");
			}
			if (count == 4 || count == 5) { // Amir : If they are DONE with the
				// fourth on the fifth it will
				// display 3rd Rakaat
				counts.setText("3rd Rakat");
			}
			if (count == 6 || count == 7) { // Amir: if they are DONE with the
				// sixth or on the seventh it will
				// display 4th rakaat
				counts.setText("4th Rakat");
			}
			if (count == 8) { // Once they complete the last sujood it will tell
				// them the prayer is complete
				counts.setText("Prayer Complete");
			}
			if (count > 8) { // If it goes over eight sujoods it will let them
				// know they are over-praying
				counts.setText("You are over-praying");
			}
		}
	}
}

